﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="TestAddDenseSymmetricMatrix.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Sequential.Tests.DenseSymmetricMatrixTest.DoubleExtensions
{
    #region Usings

    using System;

    using ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions;

    using NUnit.Framework;

    #endregion

    /// <summary>
    ///     Test suite for
    ///     <see cref="DenseSymmetricMatrixExtensions.Add(DenseSymmetricMatrix{double},DenseSymmetricMatrix{double})"/>.
    /// </summary>
    [TestFixture]
    [Category("ExulLibrary.Mathematics.LinearAlgebra.Sequential.DoubleExtensions.DenseSymmetricMatrixExtensions")]
    public sealed class TestAddDenseSymmetricMatrix
    {
        /// <summary>
        ///     Tests the method when augend and addend have the same size.
        /// </summary>
        [Test]
        public void WhenAugendAndAddendHaveTheSameSize()
        {
            // Arrange
            var addendData = new double[]
                             {
                                 1,
                                 2, 3
                             };
            var addend = new DenseSymmetricMatrix<double>(addendData);
            var augendData = new double[]
                             {
                                 10,
                                 20, 30
                             };
            var augend = new DenseSymmetricMatrix<double>(augendData);
            var expectedResult = new double[]
                                 {
                                     11,
                                     22, 33
                                 };

            // Act
            augend.Add(addend);

            // Assert
            Assert.That(augend.Values, Is.EquivalentTo(expectedResult));
        }

        /// <summary>
        ///     Tests the method when addend has less size than augend.
        /// </summary>
        [Test]
        public void WhenAddendHasLessSizeThanAugend()
        {
            // Arrange
            var addendData = new double[]
                             {
                                 1
                             };
            var addend = new DenseSymmetricMatrix<double>(addendData);
            var augendData = new double[]
                             {
                                 10,
                                 20, 30
                             };
            var augend = new DenseSymmetricMatrix<double>(augendData);
            var expectedResult = new double[]
                                 {
                                     11,
                                     20, 30
                                 };

            // Act
            augend.Add(addend);

            // Assert
            Assert.That(augend.Values, Is.EquivalentTo(expectedResult));
        }

        /// <summary>
        ///     Tests the method when addend has greater size than augend.
        /// </summary>
        [Test]
        public void WhenAddendHasGreaterSizeThanAugend()
        {
            // Arrange
            var addendData = new double[]
                             {
                                 1,
                                 2, 3,
                                 4, 5, 6
                             };
            var addend = new DenseSymmetricMatrix<double>(addendData);
            var augendData = new double[]
                             {
                                 10,
                                 20, 30
                             };
            var augend = new DenseSymmetricMatrix<double>(augendData);
            var expectedResult = new double[]
                                 {
                                     11,
                                     22, 33
                                 };

            // Act
            augend.Add(addend);

            // Assert
            Assert.That(augend.Values, Is.EquivalentTo(expectedResult));
        }

#if SAFE

        /// <summary>
        ///     Tests the method when augend is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenAugendIsNull()
        {
            // Arrange
            var addend = new DenseSymmetricMatrix<double>(3);

            // Act and Assert
            Assert.That(
                () => DenseSymmetricMatrixExtensions.Add(null, addend),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("augend"));
        }

        /// <summary>
        ///     Tests the method when addend is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenAddendIsNull()
        {
            // Arrange
            var augend = new DenseSymmetricMatrix<double>(3);

            // Act and Assert
            Assert.That(
                () => augend.Add(null),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("addend"));
        }

#endif
    }
}